package com.xiaobaibai.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.xiaobaibai.valid.AddGroup;
import com.xiaobaibai.valid.UpdateGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;

/**
 * <p>
 * 
 * </p>
 *
 * @author xiaobaibai
 * @since 2020-10-16
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("index_product")
@ApiModel(value="IndexProduct对象", description="")
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class IndexProduct implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "首页推广id")
    @TableId(value = "id", type = IdType.AUTO)
    @Null(message = "新增不可指定id",groups = AddGroup.class)
    @NotNull(message = "修改需指定id",groups = UpdateGroup.class)
    private Integer id;

    @ApiModelProperty(value = "商品id")
    @TableField("product_id")
    @NotNull(message = "商品id不可为空",groups = {AddGroup.class})
    private Integer productId;

    @ApiModelProperty(value = "商品名称")
    @TableField("product_name")
    @NotNull(message = "商品名称不可为空",groups = {AddGroup.class})
    private String productName;

    @ApiModelProperty(value = "类型:3新品4热销")
    @TableField("type")
    @NotNull(message = "类型不可为空",groups = {AddGroup.class})
    private Integer type;

    @ApiModelProperty(value = "商品图片")
    @TableField("product_image")
    @NotNull(message = "图片不可为空",groups = {AddGroup.class})
    private String productImage;

    @ApiModelProperty(value = "商品规格")
    @NotNull(message = "规格不可为空",groups = {AddGroup.class})
    @TableField("product_unit")
    private String productUnit;

    @ApiModelProperty(value = "商品原价格")
    @TableField("product_old_price")
    private BigDecimal productOldPrice;

    @ApiModelProperty(value = "商品价格")
    @NotNull(message = "价格不可为空",groups = {AddGroup.class})
    @TableField("product_price")
    private BigDecimal productPrice;

    @ApiModelProperty(value = "状态:0不显示1显示")
    @TableField("status")
    //此字段无用,因为就直接对商品删除或者添加
    private Boolean status=true;

    @ApiModelProperty(value = "创建时间")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    public Product converProduct(){
        Product product=new Product();
        product.setId(this.getProductId());
        product.setProductUnit(this.getProductUnit());
        product.setProductImage(Collections.singletonList(this.getProductImage()));
        product.setProductPrice(this.getProductPrice());
        product.setProductOldPrice(this.getProductOldPrice());
        product.setProductName(this.getProductName());
        return product;
    }

}
